package com.spa.domain.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spa.domain.entity.ApplyRefund;
import com.spa.domain.entity.Refund;
import com.spa.infrastructure.enums.dict.refund.ApplyRefundStatusEnum;
import com.spa.infrastructure.mapper.RefundMapperStruct;
import com.spa.infrastructure.repository.condition.ApplyRefundCondition;
import com.spa.infrastructure.repository.condition.RefundCondition;
import com.spa.infrastructure.repository.po.ApplyRefundPO;
import com.spa.infrastructure.repository.po.RefundPO;
import com.spa.infrastructure.repository.service.ApplyRefundRepositoryService;
import com.spa.infrastructure.repository.service.RefundRepositoryService;
import com.spa.infrastructure.service.wx.result.RefundSuccessResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RefundDomainService {

    @Autowired
    private RefundRepositoryService refundRepositoryService;

    @Autowired
    private ApplyRefundRepositoryService applyRefundRepositoryService;

    public Long add(RefundSuccessResult result) {
        RefundPO po = RefundMapperStruct.INSTANCE.command2Po(result);
        return refundRepositoryService.add(po);
    }

    public Long add(ApplyRefundPO po) {
        po.setApplyTime(new Date());
        po.setStatus(ApplyRefundStatusEnum.$10.getCode());
        return applyRefundRepositoryService.add(po);
    }

    public Page<ApplyRefund> pageApplyRefund(ApplyRefundCondition condition) {
        return applyRefundRepositoryService.page(condition);
    }

    public ApplyRefund getApplyRefund(ApplyRefundCondition condition) {
        return applyRefundRepositoryService.getApplyRefund(condition);
    }

    public List<Refund> queryRefundByOrderCodes(List<String> orderCodes) {
        RefundCondition refundCondition = new RefundCondition();
        refundCondition.setOrderCodes(orderCodes);
        return refundRepositoryService.list(refundCondition);
    }

}
